package com.example.vv.model.main;

import android.content.Context;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;

import com.example.vv.R;
import com.example.vv.frameWork.mvp.MvpActivity;
import com.example.vv.model.chat.ChatFragment;
import com.example.vv.model.home.HomeFragment;
import com.example.vv.model.main.base.adapter.FragmentAdapter;
import com.example.vv.model.main.base.contract.MainContract;
import com.example.vv.model.main.base.presenter.MainPresenter;
import com.example.vv.model.self.SelfFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainAct extends MvpActivity<MainContract.View, MainPresenter> implements BottomNavigationView.OnNavigationItemSelectedListener, MainContract.View {
    @BindView(R.id.main_view_pager)
    ViewPager mainViewPager;
    @BindView(R.id.main_navigation)
    BottomNavigationView mainNavigation;
    private int[] menu_id;
    private FragmentAdapter fragmentAdapter;
    @Override
    public int initLayout() {
        return R.layout.act_main;
    }

    @Override
    public MainPresenter initPresenter() {
        return new MainPresenter();
    }

    @Override
    public void initView() {
        mainNavigation.setItemIconTintList(null);
        // 不使用图标默认变色
        menu_id = new int[]{R.id.menu_home, R.id.menu_chat, R.id.menu_self};
        mainNavigation.setSelectedItemId(menu_id[0]);
        mainNavigation.setOnNavigationItemSelectedListener(this);
        mainViewPager.setNestedScrollingEnabled(false);
    }

    @Override
    public void initData() {
        fragmentAdapter=new FragmentAdapter(getSupportFragmentManager());
        fragmentAdapter.addFragment(new HomeFragment());
        fragmentAdapter.addFragment(new ChatFragment());
        fragmentAdapter.addFragment(new SelfFragment());
        mainViewPager.setAdapter(fragmentAdapter);
    }

    @Override
    public void doBusiness() {

    }

    @Override
    public View titleVIew() {
        return null;
    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_home:
                mainViewPager.setCurrentItem(0);
                return true;

            case R.id.menu_chat:
                mainViewPager.setCurrentItem(1);
                return true;

            case R.id.menu_self:
                mainViewPager.setCurrentItem(2);
                return true;

        }
        return false;
    }

    @Override
    public Context getMContext() {
        return this;
    }
}
